package com.drinks.yiniang.adapter.community;

import android.content.Context;
import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseViewHolder;
import com.drinks.yiniang.R;
import com.drinks.yiniang.adapter.base.BaseQuickRCVAdapter;
import com.drinks.yiniang.entity.community.CommunityDetailJson;
import com.drinks.yiniang.utils.GlideUtils;
import com.hansen.library.ui.widget.image.RatioRoundImageView;
import com.hansen.library.utils.StringUtils;

import java.util.List;

/**
 * 社区活动相关商品列表adapter
 * @author han
 * @date 2019/8/30
 */
public class CommunityGoodsAdapter extends BaseQuickRCVAdapter<CommunityDetailJson.CommunityDetailGoods, BaseViewHolder> {

    private StringBuilder mBuilder;

    public CommunityGoodsAdapter(Context mContext, @Nullable List<CommunityDetailJson.CommunityDetailGoods> data) {
        super(R.layout.item_community_goods, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, CommunityDetailJson.CommunityDetailGoods item) {
        GlideUtils.loadSquareImage(mContext, (RatioRoundImageView) helper.getView(R.id.iv_community_goods_cover), item.getCover_url());
        //名称
        helper.setText(R.id.tv_community_goods_name, item.getGoods_name());
        //价格
        mBuilder = new StringBuilder("¥");
        mBuilder.append(StringUtils.getNullEmptyConvert__(item.getId()));
        helper.setText(R.id.tv_community_goods_price, mBuilder);
        //推荐语
        helper.setText(R.id.tv_community_goods_slogan, item.getRecommend_reason());

        if(item.isChecked()) {
            helper.setImageResource(R.id.iv_community_goods_check, R.mipmap.picker_orignal_checked);
        } else {
            helper.setImageResource(R.id.iv_community_goods_check, R.mipmap.picker_orignal_normal);
        }
    }
}
